package com.test;

import java.text.DecimalFormat;
import java.util.*;

public class ShowMeBug
{
    public static HashMap<String, StudentVo> map1 = new HashMap<>();
    public static ShowMeBug showMeBug = new ShowMeBug();

    public static HashMap<String, Double> map2 = new HashMap<String, Double>()
    {
        {
            put("数学", 0.0);
            put("语文", 0.0);
            put("英语", 0.0);
            put("物理", 0.0);
        }
    };

    public static void main(String[] args)
    {
        List<ScoreVo> list1 = getScoreList();
        for (ScoreVo scoreVo : list1)
        {
            double score = scoreVo.score;
            String course = scoreVo.courseName;
            String name = scoreVo.studentName;
            map2.put(course,score+map2.get(course));
            if (map1.containsKey(name)){
                fun1(map1, score, name, course);
            }else{
                map1.put(name, showMeBug.new StudentVo());
                fun1(map1, score, name, course);
            }
        }
        Set<Map.Entry<String, StudentVo>> sets = map1.entrySet();
        List<Map.Entry<String, StudentVo>> lists = new ArrayList<>(sets);
        Collections.sort(lists, (o1, o2) -> (int) (o2.getValue().getTotalScore() - o1.getValue().getTotalScore()));
        LinkedHashMap<String, StudentVo> map = new LinkedHashMap<>();
        for (Map.Entry<String, StudentVo> entry : lists)
        {
            map.put(entry.getKey(), entry.getValue());
        }

        System.out.println("   姓名   数学   语文   英语   物理   总成绩");
        for (Map.Entry<String, StudentVo> entry : map.entrySet())
        {
            System.out.println("   " + entry.getKey() + "   " + entry.getValue().getMathScore() + "   " + entry.getValue().getChineseScore() + "   " + entry.getValue().getEnglishScore() + "   " + entry.getValue().getPhysicalScore() + "   " + entry.getValue().getTotalScore());
        }
        DecimalFormat f = new DecimalFormat("0.000");
        double math = map2.get("数学") / map.size(),
         chinese= map2.get("语文") / map.size(),
         english= map2.get("英语") / map.size(),
         physical= map2.get("物理") / map.size(),
         total= (math + chinese + english + physical);
        System.out.println(" 平均成绩" + "    " + f.format(math) + "   " + f.format(chinese) + "   " + f.format(english) + "   " + f.format(physical) + "   " + f.format(total));
    }

    public static void fun1(HashMap<String, StudentVo> map, double score, String name, String courseName)
    {
        map.get(name).setName(name);
        double totalScore = map.get(name).getTotalScore();
        map.get(name).setTotalScore(totalScore + score);
        if ("数学".equals(courseName))
        {
            map.get(name).setMathScore(score);
        }
        if ("语文".equals(courseName))
        {
            map.get(name).setChineseScore(score);
        }
        if ("英语".equals(courseName))
        {
            map.get(name).setEnglishScore(score);
        }
        if ("物理".equals(courseName))
        {
            map.get(name).setPhysicalScore(score);
        }
    }

    public static List<ScoreVo> getScoreList()
    {
        List<ScoreVo> scoreList = new ArrayList<ScoreVo>();
        ShowMeBug showMeBug = new ShowMeBug();
        scoreList.add(showMeBug.new ScoreVo("张三", "语文", 80));
        scoreList.add(showMeBug.new ScoreVo("张三", "物理", 76));
        scoreList.add(showMeBug.new ScoreVo("李四", "语文", 78));
        scoreList.add(showMeBug.new ScoreVo("茅十八", "英语", 65));
        scoreList.add(showMeBug.new ScoreVo("李四", "数学", 88));
        scoreList.add(showMeBug.new ScoreVo("李四", "物理", 87));
        scoreList.add(showMeBug.new ScoreVo("王五", "语文", 67));
        scoreList.add(showMeBug.new ScoreVo("张三", "数学", 76));
        scoreList.add(showMeBug.new ScoreVo("李四", "英语", 89));
        scoreList.add(showMeBug.new ScoreVo("王五", "数学", 65));
        scoreList.add(showMeBug.new ScoreVo("赵六", "物理", 95));
        scoreList.add(showMeBug.new ScoreVo("王五", "英语", 78));
        scoreList.add(showMeBug.new ScoreVo("王五", "物理", 65));
        scoreList.add(showMeBug.new ScoreVo("赵六", "语文", 89));
        scoreList.add(showMeBug.new ScoreVo("赵六", "英语", 87));
        scoreList.add(showMeBug.new ScoreVo("黄七", "语文", 78));
        scoreList.add(showMeBug.new ScoreVo("黄七", "数学", 65));
        scoreList.add(showMeBug.new ScoreVo("刘八", "英语", 87));
        scoreList.add(showMeBug.new ScoreVo("张三", "英语", 56));
        scoreList.add(showMeBug.new ScoreVo("黄七", "物理", 76));
        scoreList.add(showMeBug.new ScoreVo("刘八", "数学", 89));
        scoreList.add(showMeBug.new ScoreVo("黄七", "英语", 98));
        scoreList.add(showMeBug.new ScoreVo("刘八", "语文", 56));
        scoreList.add(showMeBug.new ScoreVo("刘八", "物理", 76));
        scoreList.add(showMeBug.new ScoreVo("钱九", "语文", 88));
        scoreList.add(showMeBug.new ScoreVo("钱九", "数学", 67));
        scoreList.add(showMeBug.new ScoreVo("茅十八", "数学", 43));
        scoreList.add(showMeBug.new ScoreVo("钱九", "英语", 75));
        scoreList.add(showMeBug.new ScoreVo("茅十八", "语文", 45));
        scoreList.add(showMeBug.new ScoreVo("茅十八", "物理", 56));
        return scoreList;
    }

    private class ScoreVo
    {
        public String studentName;
        public String courseName;
        public double score;

        public ScoreVo(String studentName, String courseName, double score)
        {
            this.studentName = studentName;
            this.courseName = courseName;
            this.score = score;
        }

        public String toString()
        {
            return this.studentName + "\t" + this.courseName + "\t" + this.score;
        }
    }

    private class StudentVo
    {
        private String name;
        private double chineseScore;
        private double mathScore;
        private double englishScore;
        private double physicalScore;
        private double totalScore;

        public StudentVo()
        {
        }

        public String getName()
        {
            return name;
        }

        public void setName(String name)
        {
            this.name = name;
        }

        public double getChineseScore()
        {
            return chineseScore;
        }

        public void setChineseScore(double chineseScore)
        {
            this.chineseScore = chineseScore;
        }

        public double getMathScore()
        {
            return mathScore;
        }

        public void setMathScore(double mathScore)
        {
            this.mathScore = mathScore;
        }

        public double getEnglishScore()
        {
            return englishScore;
        }

        public void setEnglishScore(double englishScore)
        {
            this.englishScore = englishScore;
        }

        public double getPhysicalScore()
        {
            return physicalScore;
        }

        public void setPhysicalScore(double physicalScore)
        {
            this.physicalScore = physicalScore;
        }

        public double getTotalScore()
        {
            return totalScore;
        }

        public void setTotalScore(double totalScore)
        {
            this.totalScore = totalScore;
        }
    }
}
